package com.runen.wnhz.runen.ui.adapter.puadapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.runen.wnhz.runen.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/6/1 0001.
 */

public class ShopListAdapter extends RecyclerView.Adapter<ShopListAdapter.ViewHolder> {

    private List<String> mShopDetailList;

    public ShopListAdapter(List<String> shopDetailList) {
        this.mShopDetailList = shopDetailList;
        if (null == mShopDetailList) {
            mShopDetailList = new ArrayList<>();
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewHolder viewHolder = null;
        View view = View.inflate(parent.getContext(), R.layout.item_shop_detail, null);
        viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        String str = mShopDetailList.get(position);
        String[] strs = str.split("：");
        String name = strs[0].toString();
        String value = strs[1].toString();
        holder.tv_name.setText(name);
        holder.tv_value.setText(value);
    }

    @Override
    public int getItemCount() {
        return mShopDetailList.size();
    }

    public void update(List<String> mShopDetailList) {
        this.mShopDetailList = mShopDetailList;
        notifyDataSetChanged();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        public TextView tv_name;
        public TextView tv_value;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_value = itemView.findViewById(R.id.tv_value);
        }
    }
}
